<?php
/**
 * icescape
 * ActionProxy.php 
 * @author   iCer <iCer@justdn.com> created on Apr 23, 2007
 * @version  $Id$
 */
class ActionProxy {
	public function invoke($action, $controller=null) {
		
		$this->initActionModel($action);
		
		
		//TODO 
		$filters = $action->getFilters();

		for($i=0; $i<sizeof($filters); $i++) {
			$filter = $filters[i];
			if ($filter instanceof Filter ) {
				$filter->preProcess();
			}
		}
		
		$result = $action->execute();
		
		for($i=0; $i<sizeof($filters); $i++) {
			$filter = $filter[i];
			if ($filter instanceof Filter ) {
				$filter->postProcess();
			}
		}
		
		$actionConfig = $action->getConfig();
		$type = $actionConfig[$result]["type"];
		
		ResultProcessorFactory::getProcessor($type)->process($action, $result, $controller);

	}
	
	/*
	 * 这里直接把提交的数据作为action的model
	 */
	public function initActionModel($action) {
		$data = ContextFactory::getContext()->getAttribute('request')->getRequest();
		$action->setModel($data);
	}
	
}

?>

